package com.medical.Controller.admin;

import com.medical.DTO.MedicalRecordsDTO;
import com.medical.DTO.MedicalRecordsPageDTO;
import com.medical.Service.MedicalRecordsService;
import com.medical.result.PageResult;
import com.medical.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin("*")
@RequestMapping("/api/admin")
@Tag(name = "医疗记录管理类")
public class MedicalRecordsController {
    @Autowired
    private MedicalRecordsService medicalRecordsService;

    /**
     * 添加医疗记录
     * @param medicalRecordsDTO
     * @return
     */
    @Operation(summary = "添加医疗记录")
    @PostMapping("/addMedicalRecords")
    public Result addMedicalRecords(@RequestBody MedicalRecordsDTO medicalRecordsDTO){
        log.info("添加医疗记录：{}", medicalRecordsDTO);
        medicalRecordsService.addMedicalRecords(medicalRecordsDTO);
        return Result.success();
    }

    /**
     * 删除医疗记录
     * @param ids
     * @return
     */
    @Operation(summary = "删除医疗记录")
    @DeleteMapping("/deleteMedicalRecords/{ids}")
    public Result deleteMedicalRecords(@PathVariable List<Integer> ids){
        log.info("删除医疗记录：{}", ids);
        medicalRecordsService.deleteMedicalRecords(ids);
        return Result.success();
    }

    /**
     * 修改医疗记录
     * @param medicalRecordsDTO
     * @return
     */
    @Operation(summary = "修改医疗记录")
    @PutMapping("/updateMedicalRecords")
    public Result updateMedicalRecords(@RequestBody MedicalRecordsDTO medicalRecordsDTO){
        log.info("修改医疗记录：{}", medicalRecordsDTO);
        medicalRecordsService.updateMedicalRecords(medicalRecordsDTO);
        return Result.success();
    }

    /**
     * 获取医疗记录列表
     * @param medicalRecordsPageDTO
     * @return
     */
    @Operation(summary = "获取医疗记录列表")
    @GetMapping("/page")
    public Result getMedicalRecordsList(MedicalRecordsPageDTO medicalRecordsPageDTO){
        log.info("获取医疗记录列表：{}", medicalRecordsPageDTO);
      PageResult page = medicalRecordsService.page(medicalRecordsPageDTO);
        return Result.success(page);
    }



}
